<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8"%>
<%@taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
<script src="../js/jquery-3.3.1.min.js"></script>
<%@include file="../common/head.jsp"%>
<script>

    function checkUserCode(proCode) {
        var flag = false;
        var msg = "请输入用户编码";
        if (proCode.value != '') {
            msg = "";
            $.ajax({
                type: "post", // 指定客户端向服务器端发送数据的方式
                url: "provider/showProviderCount", // 向服务器请求的地址
                data: {// 向服务器发送的数据
                    "proCode": proCode.value
                },
                async: false,// 是否为同步,true(默认值):异步 false:同步
                success: function (data) {// 服务器成功给予客户端响应的数据 out.print();
                    msg = "可用";
                    if (data != '0') {
                        alert("此编码已存在")
                        msg = "此编码已存在,不可用"
                    } else {
                        flag = true;
                    }
                }

            });
        }
        proCode.nextElementSibling.innerText = msg;
        return flag;
    }

    function checkDate() {
        var result = checkUserCode($("#proCode").get(0));
        return result;
    }
</script>
<div class="right">
    <div class="location">
        <strong>你现在所在的位置是:</strong>
        <span>供应商管理页面 >> 供应商添加页面</span>
    </div>
    <div class="providerAdd">
        <form:form modelAttribute="provider" id="providerForm" name="provider" method="post" action="provider/doAdd"  onsubmit="return checkDate()">
            <input type="hidden" name="method" value="add">
            <!--div的class 为error是验证错误，ok是验证成功-->
            <div class="">
                <label for="proCode">供应商编码：</label>
                <input type="text" name="proCode" id="proCode"  onblur="checkUserCode(this)" value="${requestScope.provider.proCode}">
                <!-- 放置提示信息 -->
                <font color="red"></font>
            </div>
            <div>
                <label for="proName">供应商名称：</label>
                <input type="text" name="proName" id="proName" value="${requestScope.provider.proCode}">
                <font color="red"><form:errors path="proName"/> </font>
            </div>
            <div>
                <label for="proContact">联系人：</label>
                <input type="text" name="proContact" id="proContact" value="${requestScope.provider.proCode}">
                <font color="red"></font>

            </div>
            <div>
                <label for="proPhone">联系电话：</label>
                <input type="text" name="proPhone" id="proPhone" value="${requestScope.provider.proCode}">
                <font color="red"></font>
            </div>
            <div>
                <label for="proAddress">联系地址：</label>
                <input type="text" name="proAddress" id="proAddress" value="${requestScope.provider.proCode}">
            </div>
            <div>
                <label for="proFax">传真：</label>
                <input type="text" name="proFax" id="proFax" value="${requestScope.provider.proCode}">
            </div>
            <div>
                <label for="proDesc">描述：</label>
                <input type="text" name="proDesc" id="proDesc" value="${requestScope.provider.proCode}">
            </div>
            <div class="providerAddBtn">
                <input type="submit" name="add" id="add" value="保存">
                <input type="button" id="back" name="back" value="返回" onclick="history.back()" >
            </div>
        </form:form>
    </div>
</div>
</section>
<%@include file="../common/foot.jsp" %>
